//
//  MNDInvestmentRecordListCell.m
//  minidai
//
//  Created by Steven.Yung on 2017/5/13.
//  Copyright © 2017年 迷你金服. All rights reserved.
//

#import "MNDInvestmentRecordListCell.h"

@interface MNDInvestmentRecordListCell ()

/*! 标题 */
@property (weak, nonatomic) IBOutlet UILabel *investmentTitleLabel;
/*! 投资金额 */
@property (weak, nonatomic) IBOutlet UILabel *tenderMoneyLabel;
/*! 年化收益率 */
@property (weak, nonatomic) IBOutlet UILabel *yearAprLabel;
/*! 奖励收益率 */
@property (weak, nonatomic) IBOutlet UILabel *rewardAprLabel;
/*! 是否有奖励 */
@property (weak, nonatomic) IBOutlet UIImageView *isReward;
/*! 预期收益 */
@property (weak, nonatomic) IBOutlet UILabel *expectIncomeLabel;
/*! 投资时间 */
@property (weak, nonatomic) IBOutlet UILabel *tenderTimeLabel;
/*! 投资期限 */
@property (weak, nonatomic) IBOutlet UILabel *tenderDeadline;

@property (weak, nonatomic) IBOutlet UILabel *transferFlag;
@property (weak, nonatomic) IBOutlet UIImageView *topgapView;
@property (weak, nonatomic) IBOutlet UIImageView *bottomGapView;
@property (weak, nonatomic) IBOutlet UIImageView *returnStatus;

@property (weak, nonatomic) IBOutlet UILabel *incomeTitleLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *titleLeadingConstraint;

@end

@implementation MNDInvestmentRecordListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.topgapView.image = [[UIImage imageNamed:@"investment_record_gap"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 1, 0, 1)];
    self.bottomGapView.image = [[UIImage imageNamed:@"investment_record_gap"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 1, 0, 1)];
    [self.transferFlag setHidden:YES];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)configCellWithModel:(MNDInvestmentRecordModel *)model {
    self.investmentTitleLabel.text = model.borrowTitle;
    self.tenderMoneyLabel.text = model.tenderMoney;
    self.yearAprLabel.text = [NSString stringWithFormat:@"%@%%", model.borrowYearApr];
    
    BOOL hasReward = model.sumApr.doubleValue <= 0; //小于等于0表示无奖励收益
    [self.isReward setHidden:hasReward];
    [self.rewardAprLabel setHidden:hasReward];

    self.rewardAprLabel.text = [NSString stringWithFormat:@"+%.02f%%", model.sumApr.doubleValue * 100 ];
    
    self.expectIncomeLabel.text = model.expectIncome;
    
    self.tenderTimeLabel.text = [NSString stringWithFormat:@"出借日期：%@", model.tenderAddTime];
    self.tenderDeadline.text = [NSString stringWithFormat:@"%@个月", model.borrowDeadline];
    
    //债转的标
    if (model.tenderObject.integerValue == 3) {
        [self.transferFlag setHidden:NO];
        self.titleLeadingConstraint.constant = 5;
    } else {
        [self.transferFlag setHidden:YES];
        self.titleLeadingConstraint.constant = -34;
    }
    
    if (model.tenderStatus.integerValue == 1) { //已回款
        self.tenderTimeLabel.text = [NSString stringWithFormat:@"结清日期：%@", model.borrowEndDate];
//        [self.returnStatus setHidden:NO];
//        [self.returnStatus setImage:[UIImage imageNamed:@"investment_record_completed"]];
        self.incomeTitleLabel.text = @"已获收益";
        self.expectIncomeLabel.text = model.tenderAlreadyIncome;
    } else if (model.tenderStatus.integerValue == 2) { //已转让
        self.tenderTimeLabel.text = [NSString stringWithFormat:@"结清日期：%@", model.borrowEndDate];
//        [self.returnStatus setHidden:NO];
//        [self.returnStatus setImage:[UIImage imageNamed:@"investment_record_trasfered"]];
        self.incomeTitleLabel.text = @"已获收益";
    }
    
    //提现还款
    if (model.isAdvanceReturn.integerValue == 1) {
        self.incomeTitleLabel.text = @"已获收益";
        self.tenderTimeLabel.text = [NSString stringWithFormat:@"结清日期：%@", model.advanceReturnTime];
//        [self.returnStatus setHidden:NO];
//        [self.returnStatus setImage:[UIImage imageNamed:@"investment_record_ahead"]];
    }
    
    if (model.tender_status_icon.integerValue == 1) {//提前还款
        [self.returnStatus setHidden:NO];
        [self.returnStatus setImage:[UIImage imageNamed:@"investment_record_ahead"]];
    }else if (model.tender_status_icon.integerValue == 2) {//已转让
        [self.returnStatus setHidden:NO];
        [self.returnStatus setImage:[UIImage imageNamed:@"investment_record_trasfered"]];
    }else if (model.tender_status_icon.integerValue == 3) {//已结清
        [self.returnStatus setHidden:NO];
        [self.returnStatus setImage:[UIImage imageNamed:@"investment_record_completed"]];
        
    }else if (model.tender_status_icon.integerValue == 4) {//已展期
        [self.returnStatus setHidden:NO];
        [self.returnStatus setImage:[UIImage imageNamed:@"investment_record_overdue"]];
        
    }else{
        [self.returnStatus setHidden:YES];
    }
}

@end
